{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "million-primary",
   "metadata": {},
   "outputs": [],
   "source": [
    "import gurobipy as gp\n",
    "from gurobipy import GRB\n",
    "import random\n",
    "import math\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "treated-universal",
   "metadata": {},
   "outputs": [],
   "source": [
    "tlr_miu = 0.001 # 求miu,s,b表的tolerance\n",
    "tlr_model = 0.0001 # 模型检验的tolerance\n",
    "precision = 2 # 参数保留小数点后的位数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cloudy-paradise",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 根据miu和s求b的函数\n",
    "def get_b(miu, s):\n",
    "    b = 0\n",
    "    for r in range(s):\n",
    "        b += (miu**r) * math.e**(-miu) / (math.factorial(r))\n",
    "    return b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "worth-particular",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 单调递减函数二分法求变量值\n",
    "def binary_get(aim, func=get_b, s=0, lb=0, ub=1, tlr=tlr_miu, precision=3):\n",
    "    \"\"\"\n",
    "    aim:目标值y\n",
    "    func:y=f(x)的函数f\n",
    "    s:函数的额外参数\n",
    "    lb:x的下界\n",
    "    ub:x的上界\n",
    "    tlr:算法的精度，即y的精度\n",
    "    precision:返回的x保留几位小数\n",
    "    return:给定精度下目标值y在函数func下对应的x\n",
    "    \"\"\"\n",
    "    c = (lb + ub) / 2\n",
    "    valc = func(c, s)\n",
    "    if abs(valc - aim) < tlr:\n",
    "        return round(c, precision)\n",
    "    if aim < valc:\n",
    "        return binary_get(aim, func, s, c, ub, tlr, precision)\n",
    "    return binary_get(aim, func, s, lb, c, tlr, precision)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "03bde5c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_dist_per(x1, y1, x2, y2):\n",
    "    rady1 = math.radians(y1)\n",
    "    rady2 = math.radians(y2)\n",
    "    a = rady1 - rady2\n",
    "    b = math.radians(x1) - math.radians(x2)\n",
    "    s = 2*math.asin(math.sqrt(math.sin(a/2)**2 + math.cos(rady1)*math.cos(rady2)* math.sin(b/2)**2)) * 6378.004\n",
    "    return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "preceding-bride",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获得距离矩阵\n",
    "def get_dist(group1, group2):\n",
    "    dist_mat = np.zeros([len(group1), len(group2)])\n",
    "    for i in range(len(group1)):\n",
    "        for j in range(len(group2)):\n",
    "            #dist_mat[i,j] = ((group1[i][0]-group2[j][0])**2 + (group1[i][1]-group2[j][1])**2)**0.5\n",
    "            dist_mat[i, j] = get_dist_per(group1[i][0], group1[i][1], group2[j][0], group2[j][1])\n",
    "    return dist_mat.round(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "satisfactory-chance",
   "metadata": {},
   "source": [
    "### 参数设置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "alpha-nomination",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_data = pd.read_excel(\"Test data1.xlsx\", sheet_name='data')\n",
    "df_data_t = pd.read_excel('Test data1.xlsx', sheet_name='data_t_jk')\n",
    "df_data_h = pd.read_excel('Test data1.xlsx', sheet_name='data_h_jk')\n",
    "df_data_info_cust = pd.read_excel('Test data1.xlsx', sheet_name='info_cust')\n",
    "with open('data1.txt', \"r\", encoding='utf-8') as fl:\n",
    "    C_num = int(fl.readline().split()[0])\n",
    "    J_num = int(fl.readline().split()[0])\n",
    "    I_num = int(fl.readline().split()[0])\n",
    "    M_num = int(fl.readline().split()[0])\n",
    "    virtual_num = int(fl.readline().split()[0])\n",
    "    K_num = int(fl.readline().split()[0])\n",
    "    per_cost = list(df_data.iloc[:, 1].values)\n",
    "    #per_cost = list(map(int, fl.readline().split()[0].split(\",\")))\n",
    "    h = df_data_h.values[:, 1:].astype(\"int32\")\n",
    "    \"\"\"temp = []\n",
    "    for line in fl.readline().split()[0].split(\";\"):\n",
    "        temp.append(list(map(int, line.split(\",\"))))\n",
    "    h = np.array(temp)\"\"\"\n",
    "    t = df_data_t.values[:, 1:].astype(\"int32\")\n",
    "    \"\"\"temp = []\n",
    "    for line in fl.readline().split()[0].split(\";\"):\n",
    "        temp.append(list(map(int, line.split(\",\"))))\n",
    "    t = np.array(temp)\"\"\"\n",
    "    v_1 = int(fl.readline().split()[0])\n",
    "    v_2 = list(df_data.iloc[:, 3].values.astype('int'))\n",
    "    #v_2 = list(map(int, fl.readline().split()[0].split(\",\")))\n",
    "    max_s = int(fl.readline().split()[0])\n",
    "    virtual_per_cost = list(df_data.iloc[:, 2].values.astype('int'))\n",
    "    #virtual_per_cost = list(map(int, fl.readline().split()[0].split(\",\")))\n",
    "\n",
    "with open('info_center.txt', \"r\", encoding='utf-8') as fl:\n",
    "    c_coords = []\n",
    "    for line in fl.readlines()[1:]:\n",
    "        c_coords.append(tuple(map(float, line.split()[1:])))\n",
    "\n",
    "with open('info_depot.txt', \"r\", encoding='utf-8') as fl:\n",
    "    j_coords = []\n",
    "    f = []\n",
    "    for line in fl.readlines()[1:]:\n",
    "        j_coords.append(tuple(map(float, line.split()[1:3])))\n",
    "        f.append(int(line.split()[-1]))\n",
    "\n",
    "with open('info_express.txt', \"r\", encoding='utf-8') as fl:\n",
    "    m_coords = []\n",
    "    t_res = []\n",
    "    for line in fl.readlines()[1:]:\n",
    "        m_coords.append(tuple(map(float, line.split()[1:3])))\n",
    "        t_res.append(int(line.split()[-1]))\n",
    "    for coord in j_coords:\n",
    "        m_coords.append(coord)\n",
    "        t_res.append(0)\n",
    "\n",
    "with open('info_cust1.txt', \"r\", encoding='utf-8') as fl:\n",
    "    i_coords = []\n",
    "    D = []\n",
    "    alpha = []\n",
    "    T = []\n",
    "    for line in fl.readlines()[1:]:\n",
    "        temp = line.split()\n",
    "        i_coords.append(tuple(map(float, temp[1:3])))\n",
    "        #D.append(list(map(float, temp[3].split(\",\"))))\n",
    "        #alpha.append(list(map(float, temp[4].split(\",\"))))\n",
    "        #T.append(list(map(float, temp[5].split(\",\"))))\n",
    "    D = np.array(D)\n",
    "    alpha = np.array(alpha)\n",
    "    T = np.array(T)\n",
    "    D = np.zeros((I_num, K_num))\n",
    "    alpha = np.zeros((I_num, K_num))\n",
    "    T = np.zeros((I_num, K_num))\n",
    "    for _, cust_n, prod_n, d_n, alpha_n, t_n in df_data_info_cust.itertuples(index=False):\n",
    "        D[cust_n,prod_n] = d_n\n",
    "        alpha[cust_n,prod_n] = alpha_n\n",
    "        T[cust_n,prod_n] = t_n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "buried-redhead",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.88, 0.8 , 0.9 , 0.85, 0.78, 0.88, 0.75, 0.88, 0.9 , 0.9 ],\n",
       "       [0.85, 0.78, 0.88, 0.88, 0.8 , 0.9 , 0.85, 0.83, 0.78, 0.91],\n",
       "       [0.88, 0.86, 0.89, 0.75, 0.88, 0.9 , 0.75, 0.88, 0.9 , 0.88],\n",
       "       [0.8 , 0.85, 0.83, 0.75, 0.88, 0.9 , 0.88, 0.82, 0.89, 0.9 ],\n",
       "       [0.75, 0.88, 0.9 , 0.75, 0.88, 0.9 , 0.88, 0.82, 0.89, 0.9 ],\n",
       "       [0.8 , 0.87, 0.91, 0.75, 0.88, 0.9 , 0.88, 0.82, 0.89, 0.9 ],\n",
       "       [0.86, 0.85, 0.92, 0.88, 0.82, 0.89, 0.88, 0.82, 0.89, 0.85],\n",
       "       [0.88, 0.82, 0.89, 0.86, 0.85, 0.92, 0.88, 0.79, 0.87, 0.93],\n",
       "       [0.83, 0.78, 0.91, 0.88, 0.82, 0.89, 0.88, 0.82, 0.89, 0.82],\n",
       "       [0.8 , 0.88, 0.9 , 0.88, 0.8 , 0.9 , 0.85, 0.83, 0.78, 0.94]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alpha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "welcome-elements",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"C_num = 1 # 中心库数量\n",
    "J_num = 3 # 本地库备选点数量\n",
    "I_num = 10 # 客户数量\n",
    "M_num = 8 # 快运站集合（包含虚拟点）\n",
    "virtual_num = J_num # 虚拟节点的数量，位置和本地库本选点一样\n",
    "K_num = 3 # 备件数量\n",
    "\n",
    "per_cost = [random.randint(1,6)*0.1 for _ in range(K_num)]\"\"\"\n",
    "\n",
    "C = {i for i in range(C_num)}\n",
    "I = {i for i in range(I_num)}\n",
    "J = {i for i in range(J_num)}\n",
    "M = {i for i in range(M_num)}\n",
    "K = {i for i in range(K_num)}\n",
    "\n",
    "\"\"\"c_coords = [(random.randint(0,100), random.randint(0,100))]\n",
    "i_coords = [(random.randint(0,100), random.randint(0,100)) for _ in range(len(I))]\n",
    "j_coords = [(random.randint(0,100), random.randint(0,100)) for _ in range(len(J))]\n",
    "m_coords = [(random.randint(0,100), random.randint(0,100)) for _ in range(len(M)-virtual_num)] + j_coords\n",
    "\"\"\"\n",
    "dist_ci = get_dist(c_coords, i_coords)\n",
    "dist_jm = get_dist(j_coords, m_coords)\n",
    "dist_ji = get_dist(j_coords, i_coords)\n",
    "\n",
    "\"\"\"f = []\n",
    "for j in range(len(J)):\n",
    "    f.append(random.randint(500,1500))\"\"\"\n",
    "    \n",
    "c_4 = np.zeros([len(I), len(M), len(J), len(K)])\n",
    "for i in range(len(c_4)):\n",
    "    for m in range(len(c_4[0])):\n",
    "        for j in range(len(c_4[0,0])):\n",
    "            for k in range(len(c_4[0,0,0])):\n",
    "                if m < M_num - virtual_num:\n",
    "                    c_4[i,m,j,k] = (dist_jm[j,m] + dist_ji[j,i]) * per_cost[k]\n",
    "                else:\n",
    "                    c_4[i,m,j,k] = (dist_jm[j,m] + dist_ji[j,i]) * virtual_per_cost[k]\n",
    "\n",
    "    \n",
    "c_3 = np.zeros([len(C), len(I), len(K)])\n",
    "for c in C:\n",
    "    for i in I:\n",
    "        for k in K:\n",
    "            c_3[c,i,k] = dist_ci[c,i] * virtual_per_cost[k]\n",
    "\n",
    "d_jm = dist_jm\n",
    "d_ji = dist_ji\n",
    "d_ci = dist_ci\n",
    "\n",
    "\"h = np.random.randint(10,20,size=(len(J), len(K)))\"\n",
    "\n",
    "\"D = np.random.randint(0,2,size=(len(I),len(K)))\"\n",
    "\n",
    "\"t = np.random.randint(1,3, size=(len(J), len(K)))\"\n",
    "\n",
    "\"\"\"v_1 = 1 # 本地库-快运点的行驶速度\n",
    "v_2 = [random.randint(10,20)*0.1 for _ in K]\"\"\"\n",
    "tao_jm = d_jm/v_1\n",
    "tao_jik = np.zeros((len(J), len(I), len(K)))\n",
    "for k in K:\n",
    "    tao_jik[:,:,k] = (d_ji/v_2[k]).round(2)\n",
    "\n",
    "\"alpha = np.random.random((len(I), len(K))).round(2)*0.5\"\n",
    "\n",
    "\"t_res = [random.randint(1,10)*0.1+1 for _ in M] # 快运点m的服务相应时间\"\n",
    "\n",
    "\"T = np.ones((len(I), len(K))) * 80\"\n",
    "\n",
    "\"max_s = 5\"\n",
    "L = dict() # 可用库存水平集合\n",
    "for j in J:\n",
    "    for k in K:\n",
    "        L[j,k] = set(i+1 for i in range(max_s))\n",
    "\n",
    "omega = T # 客户i对产品k要求的运输时间限制\n",
    "\n",
    "miu_lb = 0\n",
    "miu_ub = np.sum(D)*10\n",
    "\n",
    "J_ik = dict() # 能服务客户i的所有本地库备选点集合\n",
    "I_jk = dict() # 本地库j能服务的所有客户集合\n",
    "for i in I:\n",
    "    for j in J:\n",
    "        for k in K:\n",
    "            if (i,k) not in J_ik.keys():\n",
    "                J_ik[i,k] = set()\n",
    "            if (j,k) not in I_jk.keys():\n",
    "                I_jk[j,k] = set()\n",
    "            if tao_jik[j,i,k] < omega[i,k]:\n",
    "                J_ik[i,k].add(j)\n",
    "                I_jk[j,k].add(i)\n",
    "\n",
    "ijk_b = dict()\n",
    "bjk_i = dict()\n",
    "for i in I:\n",
    "    for j in J:\n",
    "        for k in K:\n",
    "            ijk_b[i,j,k] = alpha[i,k]\n",
    "for i in I:\n",
    "    for j in J:\n",
    "        for k in K:\n",
    "            b = ijk_b[i,j,k]\n",
    "            if (b,j,k) not in bjk_i.keys():\n",
    "                bjk_i[b,j,k] = i\n",
    "                \n",
    "\n",
    "                \n",
    "MC =1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "advised-illinois",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 给定一个b,i,j,k,s，求对应的miu值\n",
    "miu = dict()\n",
    "for i in I:\n",
    "    for j in J:\n",
    "        for k in K:\n",
    "            b = ijk_b[i,j,k]\n",
    "            for s in L[j,k]:\n",
    "                miu[i,j,k,s] = binary_get(b,s=s,lb=miu_lb, ub=miu_ub)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "tough-royalty",
   "metadata": {},
   "outputs": [],
   "source": [
    "i = -1\n",
    "j = -1\n",
    "k = -1\n",
    "m = -1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "taken-reaction",
   "metadata": {},
   "source": [
    "### 建模"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "played-liabilities",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using license file C:\\Users\\CYK\\gurobi.lic\n"
     ]
    }
   ],
   "source": [
    "m = gp.Model()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "quantitative-allergy",
   "metadata": {},
   "outputs": [],
   "source": [
    "y = m.addVars(len(J), vtype=GRB.BINARY)\n",
    "x = m.addVars(len(I), len(M), len(J), len(K), vtype=GRB.BINARY)\n",
    "v = m.addVars(len(J), max_s+1, len(K), vtype=GRB.BINARY)\n",
    "w = m.addVars(len(J), len(I), len(K),vtype=GRB.BINARY)\n",
    "z = m.addVars(len(I), len(M), len(J), len(I), len(K), vtype=GRB.BINARY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f9a7a93a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "# z值确定式\n",
    "m.addConstrs(z[i,m,j,n,k] - x[i,m,j,k] - w[j,n,k] >= -1 for i in I for m in M for j in J for n in I for k in K)\n",
    "m.addConstrs(z[i,m,j,n,k] - x[i,m,j,k] - w[j,n,k] <= 1 for i in I for m in M for j in J for n in I for k in K)\n",
    "m.addConstrs(z[i,m,j,n,k] - x[i,m,j,k] <= 0 for i in I for m in M for j in J for n in I for k in K)\n",
    "m.addConstrs(z[i,m,j,n,k] - w[j,n,k] <= 0 for i in I for m in M for j in J for n in I for k in K)\n",
    "print(\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "presidential-pride",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "# 当本地库开放时，才可以进行分配\n",
    "m.addConstrs(x[i,m,j,k] - y[j] <= 0 for i in I for k in K for m in M for j in J_ik[i,k])\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "tutorial-expert",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "# 每个客户需求必须且仅能分配给一个本地库和一个快运点\n",
    "m.addConstrs(gp.quicksum(gp.quicksum(x[i,m,j,k] for m in M) for j in J_ik[i,k]) == 1 for i in I for k in K)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "indonesian-newspaper",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "# 运输时间约束\n",
    "m.addConstrs(gp.quicksum(tao_jm[j,m]*x[i,m,j,k] for j in J_ik[i,k]) + \\\n",
    "            gp.quicksum(tao_jik[j,i,k]*x[i,m,j,k] for j in J_ik[i,k]) <= \\\n",
    "             T[i,k] - t_res[m] for i in I for k in K for m in M)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "sound-liberty",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "# 服务水平约束\n",
    "m.addConstrs(gp.quicksum(ijk_b[n,j,k]*w[j,n,k] for n in I) - gp.quicksum(alpha[i,k]*x[i,m,j,k] for m in M) >= 0 for i in I for k in K for j in J_ik[i,k])\n",
    "m.addConstrs(gp.quicksum(w[j,n,k] for n in I) <= 1 for j in J for k in K)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "concrete-socket",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "# 库存水平约束\n",
    "m.addConstrs(gp.quicksum(v[j,s,k] for s in L[j,k]) <= 1 for j in J for k in K)\n",
    "m.addConstrs(t[j,k] * gp.quicksum(gp.quicksum(D[i,k]*x[i,m,j,k] for i in I_jk[j,k]) for m in M) - \\\n",
    "            gp.quicksum(miu[n,j,k,s]*v[j,s,k] for s in L[j,k]) + MC*w[j,n,k] <= MC for j in J for k in K for n in I)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d04a5df",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (win64)\n",
      "Thread count: 4 physical cores, 4 logical processors, using up to 4 threads\n",
      "Optimize a model with 186760 rows, 50283 columns and 501300 nonzeros\n",
      "Model fingerprint: 0xae1aa270\n",
      "Variable types: 0 continuous, 50283 integer (50283 binary)\n",
      "Coefficient statistics:\n",
      "  Matrix range     [6e-02, 1e+03]\n",
      "  Objective range  [8e+01, 1e+05]\n",
      "  Bounds range     [1e+00, 1e+00]\n",
      "  RHS range        [1e+00, 1e+03]\n",
      "Presolve removed 48701 rows and 16741 columns (presolve time = 16s) ...\n",
      "Presolve removed 92238 rows and 16708 columns\n",
      "Presolve time: 16.52s\n",
      "Presolved: 94522 rows, 33575 columns, 245103 nonzeros\n",
      "Variable types: 0 continuous, 33575 integer (33542 binary)\n",
      "\n",
      "Deterministic concurrent LP optimizer: primal and dual simplex (primal and dual model)\n",
      "Showing first log only...\n",
      "\n",
      "\n",
      "Root simplex log...\n",
      "\n",
      "Iteration    Objective       Primal Inf.    Dual Inf.      Time\n",
      "       0    1.2545455e+04   1.315000e+02   4.052063e+09     17s\n",
      "Concurrent spin time: 0.00s\n",
      "\n",
      "Solved with dual simplex (primal model)\n",
      "\n",
      "Root relaxation: objective 7.582418e+03, 5973 iterations, 0.94 seconds\n",
      "\n",
      "    Nodes    |    Current Node    |     Objective Bounds      |     Work\n",
      " Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time\n",
      "\n",
      "     0     0 7582.41758    0 2599          - 7582.41758      -     -   30s\n",
      "H    0     0                    415564.69000 7582.41758  98.2%     -   32s\n",
      "H    0     0                    405464.69000 7582.41758  98.1%     -   32s\n",
      "H    0     0                    375596.81000 7582.41758  98.0%     -   32s\n",
      "     0     0 14606.9869    0 2281 375596.810 14606.9869  96.1%     -   43s\n",
      "     0     0 32028.2271    0 1846 375596.810 32028.2271  91.5%     -   49s\n",
      "     0     0 33185.0314    0 1564 375596.810 33185.0314  91.2%     -   49s\n",
      "     0     0 33185.0314    0 1566 375596.810 33185.0314  91.2%     -   49s\n",
      "     0     0 97381.8050    0  651 375596.810 97381.8050  74.1%     -   53s\n",
      "H    0     0                    361408.65000 97381.8050  73.1%     -   53s\n",
      "     0     0 101127.490    0  601 361408.650 101127.490  72.0%     -   55s\n",
      "     0     0 101157.330    0  358 361408.650 101157.330  72.0%     -   55s\n",
      "     0     0 101157.330    0  368 361408.650 101157.330  72.0%     -   55s\n",
      "     0     0 102979.467    0  752 361408.650 102979.467  71.5%     -   58s\n",
      "H    0     0                    361070.19000 102979.467  71.5%     -   58s\n",
      "     0     0 104057.692    0  627 361070.190 104057.692  71.2%     -   59s\n",
      "     0     0 104381.333    0  603 361070.190 104381.333  71.1%     -   59s\n",
      "     0     0 104381.333    0  597 361070.190 104381.333  71.1%     -   59s\n",
      "     0     0 105210.070    0  381 361070.190 105210.070  70.9%     -   62s\n",
      "H    0     0                    360405.97000 105210.070  70.8%     -   62s\n",
      "     0     0 105371.637    0  428 360405.970 105371.637  70.8%     -   63s\n",
      "     0     0 105531.400    0  398 360405.970 105531.400  70.7%     -   63s\n",
      "     0     0 107388.913    0  517 360405.970 107388.913  70.2%     -   63s\n",
      "     0     0 107564.125    0  432 360405.970 107564.125  70.2%     -   64s\n",
      "     0     0 107783.655    0  423 360405.970 107783.655  70.1%     -   64s\n",
      "     0     0 108133.225    0  424 360405.970 108133.225  70.0%     -   64s\n",
      "     0     0 108133.225    0  412 360405.970 108133.225  70.0%     -   64s\n",
      "     0     0 109205.822    0  883 360405.970 109205.822  69.7%     -   67s\n",
      "H    0     0                    359974.01000 109205.822  69.7%     -   67s\n",
      "     0     0 109677.871    0  702 359974.010 109677.871  69.5%     -   68s\n",
      "     0     0 109988.794    0  684 359974.010 109988.794  69.4%     -   68s\n",
      "     0     0 110157.952    0  641 359974.010 110157.952  69.4%     -   68s\n",
      "     0     0 110157.952    0  633 359974.010 110157.952  69.4%     -   68s\n",
      "     0     0 111911.265    0  430 359974.010 111911.265  68.9%     -   70s\n",
      "H    0     0                    269332.60000 111911.265  58.4%     -   70s\n",
      "H    0     0                    259318.81000 111911.265  56.8%     -   70s\n",
      "     0     0 112425.495    0  441 259318.810 112425.495  56.6%     -   71s\n",
      "     0     0 112628.519    0  770 259318.810 112628.519  56.6%     -   71s\n",
      "     0     0 113047.260    0  444 259318.810 113047.260  56.4%     -   71s\n",
      "     0     0 113094.990    0  449 259318.810 113094.990  56.4%     -   71s\n",
      "     0     0 113141.280    0  421 259318.810 113141.280  56.4%     -   72s\n",
      "     0     0 116419.175    0  742 259318.810 116419.175  55.1%     -   74s\n",
      "H    0     0                    259078.33000 116419.175  55.1%     -   74s\n",
      "     0     0 116629.040    0  508 259078.330 116629.040  55.0%     -   75s\n",
      "     0     0 116643.493    0  788 259078.330 116643.493  55.0%     -   75s\n",
      "     0     0 122189.143    0  485 259078.330 122189.143  52.8%     -   77s\n",
      "H    0     0                    256159.17000 122189.143  52.3%     -   77s\n",
      "     0     0 122596.163    0  536 256159.170 122596.163  52.1%     -   77s\n",
      "     0     0 122675.203    0  550 256159.170 122675.203  52.1%     -   78s\n",
      "     0     0 122817.189    0  838 256159.170 122817.189  52.1%     -   78s\n",
      "     0     0 122926.197    0  552 256159.170 122926.197  52.0%     -   78s\n",
      "     0     0 122926.197    0  545 256159.170 122926.197  52.0%     -   78s\n",
      "     0     0 125520.022    0  833 256159.170 125520.022  51.0%     -   80s\n",
      "     0     0 126414.534    0  788 256159.170 126414.534  50.7%     -   81s\n",
      "     0     0 126476.506    0  807 256159.170 126476.506  50.6%     -   81s\n",
      "     0     0 126532.443    0  812 256159.170 126532.443  50.6%     -   82s\n",
      "     0     0 126604.914    0  800 256159.170 126604.914  50.6%     -   82s\n",
      "     0     0 126628.197    0  812 256159.170 126628.197  50.6%     -   82s\n",
      "     0     0 128540.255    0  541 256159.170 128540.255  49.8%     -   83s\n",
      "     0     0 128958.065    0  502 256159.170 128958.065  49.7%     -   84s\n",
      "     0     0 128969.388    0  789 256159.170 128969.388  49.7%     -   84s\n",
      "     0     0 129292.638    0  487 256159.170 129292.638  49.5%     -   86s\n",
      "     0     0 129320.838    0  515 256159.170 129320.838  49.5%     -   86s\n",
      "     0     0 129575.300    0  534 256159.170 129575.300  49.4%     -   88s\n",
      "     0     0 129708.830    0  545 256159.170 129708.830  49.4%     -   88s\n",
      "     0     0 129708.830    0  563 256159.170 129708.830  49.4%     -   89s\n",
      "     0     0 130070.115    0  809 256159.170 130070.115  49.2%     -   90s\n",
      "     0     0 130245.752    0  821 256159.170 130245.752  49.2%     -   91s\n",
      "     0     0 130387.562    0  861 256159.170 130387.562  49.1%     -   91s\n",
      "     0     0 130401.022    0  853 256159.170 130401.022  49.1%     -   92s\n",
      "     0     0 131067.850    0  826 256159.170 131067.850  48.8%     -   93s\n",
      "     0     0 131110.785    0  899 256159.170 131110.785  48.8%     -   94s\n",
      "     0     0 131135.744    0  919 256159.170 131135.744  48.8%     -   94s\n",
      "     0     0 131523.723    0  895 256159.170 131523.723  48.7%     -   96s\n",
      "     0     0 131544.358    0  898 256159.170 131544.358  48.6%     -   98s\n",
      "     0     0 131971.159    0  888 256159.170 131971.159  48.5%     -   99s\n",
      "     0     0 132024.380    0  904 256159.170 132024.380  48.5%     -  100s\n",
      "     0     0 132026.565    0  918 256159.170 132026.565  48.5%     -  100s\n",
      "     0     0 132041.839    0  957 256159.170 132041.839  48.5%     -  102s\n",
      "     0     0 132069.498    0  951 256159.170 132069.498  48.4%     -  104s\n",
      "     0     0 132151.517    0  989 256159.170 132151.517  48.4%     -  106s\n",
      "     0     0 132151.517    0  693 256159.170 132151.517  48.4%     -  107s\n",
      "H    0     0                    255803.55000 132151.517  48.3%     -  111s\n",
      "     0     2 132151.517    0  690 255803.550 132151.517  48.3%     -  114s\n",
      "     1     4 132254.521    1  484 255803.550 132216.658  48.3%  3669  115s\n",
      "H   27    28                    255803.54996 152737.080  40.3%   465  118s\n",
      "H   29    28                    255803.54914 152737.080  40.3%   434  119s\n",
      "    83    82 227258.333   12  383 255803.549 152737.080  40.3%   160  121s\n",
      "   126   113 233414.949   18  458 255803.549 152737.080  40.3%   115  125s\n",
      "   342   321 244386.222   45  447 255803.549 152737.080  40.3%  62.9  131s\n",
      "   443   423 245188.488   54  442 255803.549 152737.080  40.3%  52.0  135s\n",
      "H  510   479                    255794.69000 152737.080  40.3%  47.2  139s\n",
      "   549   497 248409.061   67  435 255794.690 152737.080  40.3%  45.0  141s\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   681   547 247493.515   79  440 255794.690 152737.080  40.3%  38.9  157s\n",
      "H  688   547                    255794.68989 152737.080  40.3%  38.5  157s\n",
      "H  830   615                    255779.29000 161633.052  36.8%  35.9  162s\n",
      "   980   736 229846.499   47  382 255779.290 161633.052  36.8%  32.9  165s\n",
      "  1025   737 176961.216   36  693 255779.290 161633.052  36.8%  32.8  181s\n",
      "  1027   738 245285.988   57  236 255779.290 161633.052  36.8%  32.7  185s\n",
      "  1028   739 242609.452   36  287 255779.290 161633.052  36.8%  32.7  191s\n",
      "  1029   740 165347.058   16  391 255779.290 161633.052  36.8%  32.6  195s\n",
      "  1032   742 252890.362   55  357 255779.290 161633.052  36.8%  32.5  200s\n",
      "  1035   744 235620.340   29  344 255779.290 161633.052  36.8%  32.4  208s\n",
      "  1036   744 246512.315   35  565 255779.290 161633.052  36.8%  32.4  210s\n",
      "  1039   746 248712.055   82  623 255779.290 161633.052  36.8%  32.3  215s\n",
      "  1042   748 165255.311   32  646 255779.290 161633.052  36.8%  32.2  220s\n",
      "  1044   750 242607.621   71  810 255779.290 161633.052  36.8%  32.2  225s\n",
      "  1048   752 251612.182  104  756 255779.290 161633.052  36.8%  32.0  230s\n",
      "H 1049   714                    254779.29000 161633.052  36.6%  32.0  239s\n",
      "  1051   715 214092.748   14  795 254779.290 161633.052  36.6%  32.0  240s\n",
      "  1054   717 163490.182   16  732 254779.290 161633.052  36.6%  31.9  250s\n",
      "  1057   719 242235.294   61  798 254779.290 161633.052  36.6%  31.8  263s\n",
      "  1058   720 242182.071   67  917 254779.290 184999.997  27.4%  31.7  271s\n",
      "  1059   721 244675.430   48  807 254779.290 187523.001  26.4%  31.7  287s\n",
      "  1060   721 238532.074   50  759 254779.290 187523.001  26.4%  31.7  291s\n",
      "  1062   726 187523.001   15  511 254779.290 187523.001  26.4%  86.4  306s\n",
      "  1064   729 187523.001   16  674 254779.290 187523.001  26.4%  87.0  313s\n",
      "  1068   730 infeasible   17      254779.290 187523.001  26.4%  88.5  315s\n",
      "  1080   736 214717.347   18  334 254779.290 187523.001  26.4%  95.4  320s\n",
      "H 1091   701                    254779.28992 187523.001  26.4%   100  322s\n",
      "  1101   710 215351.002   21  363 254779.290 187523.001  26.4%   101  325s\n",
      "H 1121   688                    254779.28934 187523.001  26.4%   100  330s\n",
      "H 1122   655                    254779.28928 187523.001  26.4%   100  330s\n",
      "  1153   676 220970.844   27  371 254779.289 187523.001  26.4%  98.5  336s\n",
      "  1189   703 224726.021   32  327 254779.289 187523.001  26.4%  97.1  341s\n",
      "  1221   725 235958.707   36  293 254779.289 187523.001  26.4%  94.9  347s\n",
      "  1249   746 227444.015   39  300 254779.289 187523.001  26.4%  93.3  350s\n",
      "  1292   772 228561.373   44  276 254779.289 187523.001  26.4%  90.8  358s\n",
      "  1312   791 229395.121   46  268 254779.289 187523.001  26.4%  89.7  360s\n",
      "  1353   816 229974.185   52  272 254779.289 187523.001  26.4%  87.2  365s\n",
      "  1384   832 232957.710   57  253 254779.289 187523.001  26.4%  85.6  371s\n",
      "  1435   870 infeasible   63      254779.289 187523.001  26.4%  83.1  375s\n",
      "  1476   883 237232.266   69  228 254779.289 187523.001  26.4%  81.1  381s\n",
      "H 1531   861                    254779.28891 187523.001  26.4%  78.5  383s\n",
      "  1535   877 239276.290   77  181 254779.289 187523.001  26.4%  78.3  385s\n",
      "  1587   899 240042.420   83  181 254779.289 187523.001  26.4%  76.1  390s\n",
      "  1644   921 242031.433   89  206 254779.289 187523.001  26.4%  73.9  397s\n",
      "  1700   952 245806.248   97  145 254779.289 187523.001  26.4%  73.7  404s\n",
      "  1723   972 247590.725  101  147 254779.289 187523.001  26.4%  73.0  407s\n",
      "  1751   987 248095.488  106  146 254779.289 187523.001  26.4%  72.3  410s\n",
      "  1824  1005 223282.685   23  399 254779.289 214717.347  15.7%  70.7  419s\n",
      "  1850  1031 238637.742   31  254 254779.289 214717.347  15.7%  70.2  422s\n",
      "  1885  1057 244509.590   41  187 254779.289 214717.347  15.7%  69.3  425s\n",
      "  1965  1109 247088.321   62  180 254779.289 214717.347  15.7%  66.9  432s\n",
      "  2008  1129 249491.829   72  130 254779.289 214717.347  15.7%  65.6  435s\n",
      "  2111  1174 252423.061   98   35 254779.289 214717.347  15.7%  63.2  444s\n",
      "  2153  1201 252594.201  108   35 254779.289 214717.347  15.7%  62.4  447s\n",
      "  2212  1229 232813.721   37  293 254779.289 214717.347  15.7%  60.9  452s\n",
      "  2264  1265 237655.932   45  263 254779.289 214717.347  15.7%  60.0  456s\n",
      "  2330  1296 239798.565   52  263 254779.289 214717.347  15.7%  58.8  460s\n",
      "  2397  1309 243261.482   63  194 254779.289 214717.347  15.7%  57.5  469s\n",
      "  2448  1347 243727.258   67  198 254779.289 214717.347  15.7%  56.9  473s\n",
      "  2509  1387 245217.032   83  193 254779.289 214717.347  15.7%  56.1  480s\n",
      "  2647  1474 247141.367  101  138 254779.289 214717.347  15.7%  53.9  492s\n",
      "  2719  1503 247897.574  115  131 254779.289 214717.347  15.7%  52.8  496s\n",
      "  2814  1531 248154.237  132  129 254779.289 214717.347  15.7%  51.5  504s\n",
      "  2897  1597 248338.435  145  132 254779.289 214717.347  15.7%  50.6  511s\n",
      "  2976  1653 249494.581  162  108 254779.289 216336.181  15.1%  49.7  520s\n",
      "  3063  1721 229412.567   22  325 254779.289 216650.392  15.0%  49.2  526s\n",
      "  3138  1797 234133.107   31  292 254779.289 216650.392  15.0%  49.1  534s\n",
      "  3218  1877 237702.298   41  228 254779.289 216650.392  15.0%  48.3  539s\n",
      "  3304  1959 243837.781   52  187 254779.289 216650.392  15.0%  47.3  548s\n",
      "  3394  2039 248282.417   65  128 254779.289 216957.089  14.8%  46.3  559s\n",
      "  3495  2121 224377.909   22  409 254779.289 216957.089  14.8%  45.4  565s\n",
      "  3605  2194 243257.963   44  253 254779.289 216957.089  14.8%  44.5  575s\n",
      "  3722  2281 251563.135   72  173 254779.289 217349.538  14.7%  43.4  585s\n",
      "  3828  2380 240440.702   32  231 254779.289 218378.650  14.3%  42.9  594s\n",
      "  3967  2498 infeasible   45      254779.289 219121.948  14.0%  42.2  604s\n",
      "  4098  2596 253311.063   44  200 254779.289 219174.175  14.0%  41.4  613s\n",
      "  4252  2711 240196.878   38  250 254779.289 219526.308  13.8%  40.9  622s\n",
      "  4378  2813 247877.415   70  188 254779.289 219535.642  13.8%  40.0  633s\n",
      "  4526  2924 240747.471   41  267 254779.289 219957.551  13.7%  39.9  644s\n",
      "  4675  3032 230825.913   22  346 254779.289 219957.551  13.7%  39.2  655s\n",
      "  4830  3131 249596.646   60  213 254779.289 220046.977  13.6%  38.8  668s\n",
      "  5010  3257 250160.123   44  179 254779.289 220271.347  13.5%  38.9  681s\n",
      "  5174  3398 234680.460   28  372 254779.289 220465.205  13.5%  38.8  694s\n",
      "  5334  3538 249126.925   42  219 254779.289 220583.802  13.4%  38.6  709s\n",
      "  5499  3689 234905.818   36  303 254779.289 220583.802  13.4%  38.1  724s\n",
      "  5669  3845 239072.164   56  226 254779.289 220583.802  13.4%  37.5  738s\n",
      "  5878  3990 246100.017   79  170 254779.289 220775.719  13.3%  37.1  754s\n",
      "H 5980  3961                    254309.73000 220908.919  13.1%  36.8  754s\n",
      "  6081  4146 234001.391   32  347 254309.730 220970.844  13.1%  36.6  767s\n",
      "  6332  4337 252342.341   33  255 254309.730 221500.933  12.9%  36.3  781s\n",
      "  6585  4496 253437.731   71  164 254309.730 221905.030  12.7%  35.5  796s\n",
      "H 6747  4496                    254309.72971 221923.611  12.7%  35.4  796s\n",
      "  6800  4694 227648.287   23  430 254309.730 222155.547  12.6%  35.3  809s\n",
      "  7079  4897 233783.608   31  350 254309.730 222330.941  12.6%  34.7  825s\n",
      "  7355  5100 249353.334   48  278 254309.730 222506.123  12.5%  34.3  841s\n",
      "  7636  5309 239197.950   35  300 254309.730 222900.415  12.4%  34.0  856s\n",
      "  7955  5549 250566.960   36  250 254309.730 223464.039  12.1%  33.7  874s\n",
      "  8296  5764 253149.585   53  157 254309.730 223699.054  12.0%  33.5  892s\n",
      "  8622  6022 246360.161   30  338 254309.730 223966.838  11.9%  33.5  909s\n",
      "  8986  6275 235359.754   28  401 254309.730 224257.902  11.8%  33.2  926s\n",
      "  9360  6492 230846.631   28  383 254309.730 224436.684  11.7%  32.9  942s\n",
      "  9756  6756 252074.435   51  233 254309.730 224607.100  11.7%  32.4  963s\n",
      " 10131  7070 250930.702   64  227 254309.730 224951.903  11.5%  32.2  981s\n",
      " 10564  7361 246150.226   27  305 254309.730 225130.325  11.5%  31.8 1014s\n",
      "H10682  7361                    254309.72926 225130.325  11.5%  31.7 1014s\n",
      " 11017  7660 250810.310   55  238 254309.729 225423.139  11.4%  31.6 1034s\n",
      " 11381  7954 252830.102   42  234 254309.729 225526.587  11.3%  31.5 1052s\n",
      " 11790  8251 239855.642   29  395 254309.729 225815.385  11.2%  31.2 1072s\n",
      " 12229  8501     cutoff   49      254309.729 225914.486  11.2%  30.8 1093s\n",
      " 12620  8746 248042.580   47  309 254309.729 226162.041  11.1%  31.0 1113s\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 13045  9024     cutoff   60      254309.729 226316.662  11.0%  30.9 1130s\n",
      " 13457  9268 249868.446   48  236 254309.729 226470.442  10.9%  30.8 1149s\n",
      " 13848  9506 infeasible   46      254309.729 226586.288  10.9%  30.8 1167s\n",
      " 14239  9753 248834.795   36  325 254309.729 226696.028  10.9%  30.8 1188s\n",
      " 14636 10036 249307.139   60  259 254309.729 226889.095  10.8%  30.6 1206s\n",
      " 15047 10299 253855.745   77  104 254309.729 226967.465  10.8%  30.5 1225s\n",
      " 15438 10581 250190.422   38  301 254309.729 227068.872  10.7%  30.4 1243s\n",
      " 15845 10827     cutoff   47      254309.729 227157.501  10.7%  30.3 1261s\n",
      "H16138 10827                    254309.72873 227195.403  10.7%  30.3 1261s\n",
      " 16244 11065 231601.371   25  431 254309.729 227298.272  10.6%  30.3 1281s\n",
      " 16662 11366 239831.382   30  355 254309.729 227441.553  10.6%  30.3 1304s\n",
      "H16720 11366                    254309.72837 227441.553  10.6%  30.2 1304s\n",
      " 16957 11366 253182.616   33  218 254309.728 227465.353  10.6%  30.1 1305s\n",
      " 17056 11626 248600.685   42  287 254309.728 227471.176  10.6%  30.1 1326s\n",
      " 17461 11895 253437.261   65  247 254309.728 227594.143  10.5%  29.9 1345s\n",
      " 17850 12182 243143.509   48  288 254309.728 227732.131  10.5%  29.9 1364s\n",
      " 18250 12459 229946.291   32  429 254309.728 227795.403  10.4%  29.7 1384s\n",
      " 18634 12695 infeasible   57      254309.728 227844.257  10.4%  29.6 1421s\n",
      " 19003 12971 250542.445   54  258 254309.728 227954.558  10.4%  29.7 1441s\n",
      " 19353 13219     cutoff   55      254309.728 228011.595  10.3%  29.8 1459s\n",
      " 19765 13457 234251.356   28  434 254309.728 228131.896  10.3%  29.8 1479s\n",
      " 20161 13731 249711.960   52  284 254309.728 228246.713  10.2%  29.8 1499s\n",
      " 20547 14002 245182.086   33  373 254309.728 228307.426  10.2%  29.8 1519s\n",
      " 20941 14309 249942.767   51  245 254309.728 228372.225  10.2%  29.8 1681s\n",
      " 21386 14559 250459.028   39  256 254309.728 228445.099  10.2%  29.8 1701s\n",
      " 21775 14821 infeasible   61      254309.728 228497.549  10.1%  29.8 1718s\n",
      " 22172 15122 245257.570   33  305 254309.728 228579.806  10.1%  29.8 1736s\n",
      " 22594 15386 infeasible   51      254309.728 228654.920  10.1%  29.8 1771s\n",
      " 22987 15609 241800.273   39  290 254309.728 228828.964  10.0%  29.8 1792s\n",
      " 23390 15878 248417.411   39  209 254309.728 228949.154  10.0%  29.8 1810s\n",
      " 23793 16108 240073.843   40  370 254309.728 229001.876  10.0%  29.8 1830s\n",
      " 24228 16365 241976.196   33  357 254309.728 229125.578  9.90%  29.8 1849s\n",
      " 24640 16607 247461.875   37  277 254309.728 229178.441  9.88%  29.8 1867s\n",
      " 25038 16808 252704.560   35  223 254309.728 229256.879  9.85%  29.8 1887s\n",
      " 25434 17057 239274.470   31  375 254309.728 229396.016  9.80%  29.9 1912s\n",
      " 25851 17299 241603.050   32  362 254309.728 229432.215  9.78%  30.1 1936s\n",
      " 26260 17544 253625.471   45  271 254309.728 229463.590  9.77%  30.0 1955s\n",
      " 26687 17768 238238.280   40  298 254309.728 229532.114  9.74%  29.9 1973s\n",
      " 27087 18013 253772.097   46  203 254309.728 229596.923  9.72%  30.0 1991s\n",
      " 27510 18251 241832.748   27  355 254309.728 229697.547  9.68%  30.1 2016s\n",
      " 27920 18497 247563.476   41  242 254309.728 229758.424  9.65%  30.2 2034s\n",
      " 28340 18770 243475.760   30  349 254309.728 229827.241  9.63%  30.2 2051s\n",
      " 28765 19017 241363.787   28  416 254309.728 229884.408  9.60%  30.1 2067s\n",
      " 29165 19309 248558.132   57  195 254309.728 229985.792  9.56%  30.2 2083s\n",
      " 29564 19425 249659.469   80  145 254309.728 230004.916  9.56%  30.1 2287s\n",
      " 29765 19655 250848.783   39  234 254309.728 230030.642  9.55%  30.1 2304s\n",
      " 30197 19888 234762.421   31  449 254309.728 230113.121  9.51%  30.2 2325s\n",
      " 30615 20164 242781.705   29  335 254309.728 230196.926  9.48%  30.3 2344s\n",
      " 31030 20461 247750.634   35  329 254309.728 230228.223  9.47%  30.2 2363s\n",
      " 31436 20762 250142.887   50  270 254309.728 230325.900  9.43%  30.2 2404s\n",
      " 31851 21068 249353.265   39  317 254309.728 230414.381  9.40%  30.2 2424s\n",
      " 32298 21293 252287.834   93   96 254309.728 230451.626  9.38%  30.1 2442s\n",
      " 32737 21571 244092.657   31  343 254309.728 230526.560  9.35%  30.1 2460s\n",
      " 33136 21819 243057.623   33  332 254309.728 230605.266  9.32%  30.1 2479s\n",
      " 33546 22056 251154.094   77  258 254309.728 230655.903  9.30%  30.1 2499s\n",
      " 33942 22343 244262.368   29  380 254309.728 230714.085  9.28%  30.2 2517s\n",
      " 34356 22606 253360.509   52  243 254309.728 230797.122  9.25%  30.1 2544s\n",
      " 34749 22838 248674.174   33  281 254309.728 230852.401  9.22%  30.1 2570s\n",
      " 35153 23066     cutoff   40      254309.728 230921.746  9.20%  30.1 2593s\n",
      " 35550 23299 237679.812   27  347 254309.728 230965.280  9.18%  30.2 2615s\n",
      " 35960 23540 247263.838   46  217 254309.728 231014.381  9.16%  30.2 2638s\n",
      " 36364 23759 240483.269   31  422 254309.728 231088.153  9.13%  30.3 2675s\n",
      " 36752 23989 243065.105   30  399 254309.728 231142.335  9.11%  30.3 2695s\n",
      " 37168 24202 252103.403   56  200 254309.728 231179.593  9.10%  30.3 2716s\n",
      " 37592 24451 252581.002   42  208 254309.728 231225.525  9.08%  30.3 2737s\n",
      " 38016 24703 250537.589   46  235 254309.728 231301.108  9.05%  30.3 2759s\n",
      " 38437 24903 250904.892   46  290 254309.728 231329.580  9.04%  30.3 2780s\n",
      " 38882 25125 infeasible   78      254309.728 231390.889  9.01%  30.3 2799s\n",
      " 39313 25397 244286.519   35  367 254309.728 231458.033  8.99%  30.3 2826s\n",
      " 39711 25645 233487.577   26  474 254309.728 231467.873  8.98%  30.3 2845s\n",
      " 40110 25908 246827.125   31  337 254309.728 231554.124  8.95%  30.3 2867s\n",
      " 40506 26201 252694.964   34  292 254309.728 231617.007  8.92%  30.2 2888s\n",
      " 40906 26433 infeasible   42      254309.728 231655.299  8.91%  30.2 2915s\n",
      " 41290 26720 240286.000   31  391 254309.728 231689.632  8.89%  30.2 2950s\n",
      " 41681 26979 251757.482   71  207 254309.728 231700.541  8.89%  30.1 2984s\n",
      " 42128 27171 252006.308   45  305 254309.728 231771.842  8.86%  30.1 3010s\n",
      " 42542 27433 247194.061   39  285 254309.728 231822.356  8.84%  30.1 3029s\n",
      " 42928 27668 243497.674   38  334 254309.728 231858.294  8.83%  30.1 3052s\n",
      " 43332 27900 238324.216   35  374 254309.728 231917.717  8.81%  30.1 3071s\n",
      " 43763 28154 240160.174   27  440 254309.728 231976.592  8.78%  30.1 3101s\n",
      " 44146 28376 241668.601   29  339 254309.728 231996.385  8.77%  30.0 3126s\n",
      " 44567 28656 251811.755   35  240 254309.728 232053.359  8.75%  30.1 3147s\n",
      " 44968 28869 253260.255   68  149 254309.728 232090.621  8.74%  30.0 3168s\n",
      " 45368 29072 250626.734   43  289 254309.728 232146.580  8.72%  30.0 3198s\n",
      " 45775 29344     cutoff   45      254309.728 232203.976  8.69%  30.0 3219s\n",
      " 46174 29587 244909.327   35  325 254309.728 232243.290  8.68%  30.0 3279s\n",
      " 46531 29873 249771.735   49  250 254309.728 232271.477  8.67%  29.9 3301s\n",
      " 46947 30127 251743.560   62  231 254309.728 232299.139  8.66%  29.9 3329s\n",
      " 47352 30398 242959.695   30  382 254309.728 232367.848  8.63%  29.9 3351s\n",
      " 47757 30632 243225.588   32  350 254309.728 232423.394  8.61%  29.8 3372s\n",
      " 48171 30837 245057.789   34  324 254309.728 232483.057  8.58%  29.8 3413s\n",
      " 48577 31077 241558.577   34  334 254309.728 232557.710  8.55%  29.8 3432s\n",
      " 49007 31312 249820.697   43  296 254309.728 232609.702  8.53%  29.8 3454s\n",
      " 49418 31569 250042.787   60  149 254309.728 232630.992  8.52%  29.8 3485s\n",
      " 49821 31824 253784.967   45  271 254309.728 232656.290  8.51%  29.8 3509s\n",
      " 50230 32126 249486.084   38  270 254309.728 232683.868  8.50%  29.8 3532s\n",
      " 50624 32341 249443.248   43  273 254309.728 232701.775  8.50%  29.8 3557s\n",
      " 51046 32558 252706.397   49  226 254309.728 232728.982  8.49%  29.7 3600s\n",
      " 51439 32800 243682.112   30  367 254309.728 232749.470  8.48%  29.7 3627s\n",
      " 51831 33064 235304.023   31  442 254309.728 232794.273  8.46%  29.7 3650s\n",
      " 52232 33358 infeasible   58      254309.728 232828.940  8.45%  29.7 3694s\n",
      " 52663 33589 252597.433   61  184 254309.728 232855.859  8.44%  29.6 3714s\n",
      " 53091 33813 251673.849   52  259 254309.728 232877.346  8.43%  29.7 3756s\n",
      " 53480 34084 243231.486   34  338 254309.728 232901.678  8.42%  29.7 3779s\n",
      " 53886 34273 237305.975   37  400 254309.728 232936.481  8.40%  29.6 3803s\n",
      " 54296 34510 infeasible   29      254309.728 232993.662  8.38%  29.7 3839s\n",
      " 54693 34730 infeasible   83      254309.728 233020.962  8.37%  29.7 3860s\n",
      " 55103 34937 252221.928   62  175 254309.728 233059.289  8.36%  29.8 3881s\n",
      " 55540 35140 251745.048   37  253 254309.728 233102.959  8.34%  29.8 3907s\n",
      " 55940 35394 250339.873   36  255 254309.728 233140.744  8.32%  29.8 3953s\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 56345 35694 243412.991   33  381 254309.728 233173.697  8.31%  29.8 3975s\n",
      " 56741 35929 infeasible   69      254309.728 233184.681  8.31%  29.8 3996s\n",
      " 57135 36195 250445.893   47  293 254309.728 233231.258  8.29%  29.7 4023s\n",
      " 57529 36467 247071.155   40  319 254309.728 233255.210  8.28%  29.7 4055s\n",
      " 57928 36714 252388.805   60  132 254309.728 233284.883  8.27%  29.7 4098s\n",
      " 58339 36932 237793.114   32  390 254309.728 233317.339  8.25%  29.7 4123s\n",
      " 58741 37107 246960.764   37  312 254309.728 233354.808  8.24%  29.7 4159s\n",
      " 59168 37346 infeasible   42      254309.728 233377.345  8.23%  29.7 4185s\n",
      " 59584 37611 248863.706   37  321 254309.728 233415.341  8.22%  29.7 4219s\n",
      " 60001 37882 248264.855   32  314 254309.728 233434.152  8.21%  29.7 4242s\n",
      " 60413 38115 252934.735   45  193 254309.728 233458.229  8.20%  29.7 4269s\n",
      " 60617 38115 infeasible   87      254309.728 233470.252  8.19%  29.7 4270s\n",
      " 60809 38418 253740.049   51  242 254309.728 233497.661  8.18%  29.7 4306s\n",
      " 61200 38658     cutoff   42      254309.728 233502.087  8.18%  29.6 4341s\n",
      " 61630 38886 252157.943   34  256 254309.728 233545.423  8.16%  29.6 4364s\n",
      " 62014 39115 248696.131   66  246 254309.728 233577.846  8.15%  29.6 4401s\n",
      " 62400 39328 253274.930   69  200 254309.728 233604.493  8.14%  29.6 4437s\n",
      " 62806 39538 254075.710   72  201 254309.728 233645.520  8.13%  29.6 4479s\n",
      " 63259 39743 252461.443   57  156 254309.728 233691.523  8.11%  29.6 4506s\n",
      " 63662 39946 251457.869   38  269 254309.728 233738.246  8.09%  29.7 4543s\n",
      " 64052 40192 249704.533   32  344 254309.728 233783.408  8.07%  29.7 4565s\n",
      " 64436 40438 253462.067   36  265 254309.728 233824.822  8.06%  29.7 4584s\n",
      " 64862 40630 251288.964   46  307 254309.728 233858.150  8.04%  29.7 4628s\n",
      " 65266 40854 249829.624   31  299 254309.728 233886.280  8.03%  29.7 4670s\n",
      " 65658 41102 243682.869   31  416 254309.728 233917.115  8.02%  29.7 4695s\n",
      " 66080 41343 241490.232   34  333 254309.728 233945.272  8.01%  29.6 4717s\n",
      " 66490 41560 infeasible   55      254309.728 233966.098  8.00%  29.6 4738s\n",
      " 66895 41795 245591.079   29  381 254309.728 233992.492  7.99%  29.6 4778s\n",
      " 67281 42052 253790.543   62  134 254309.728 234000.884  7.99%  29.6 4801s\n",
      " 67679 42267 239477.845   32  457 254309.728 234025.654  7.98%  29.5 4827s\n",
      " 68097 42429 253085.491   57  188 254309.728 234052.935  7.97%  29.5 4860s\n",
      " 68511 42649 240980.108   27  411 254309.728 234107.984  7.94%  29.5 4893s\n",
      " 68916 42897 249514.686   88  292 254309.728 234124.985  7.94%  29.5 4919s\n",
      " 69307 43111     cutoff   44      254309.728 234148.033  7.93%  29.5 4958s\n",
      " 69709 43375 infeasible   61      254309.728 234171.500  7.92%  29.5 5032s\n",
      " 70102 43635 249881.642   64  114 254309.728 234198.933  7.91%  29.4 5055s\n",
      " 70497 43900 238003.496   33  360 254309.728 234221.053  7.90%  29.4 5100s\n",
      " 70903 44180 243548.794   33  396 254309.728 234245.817  7.89%  29.4 5123s\n",
      " 71311 44430 252943.235   51  233 254309.728 234281.268  7.88%  29.3 5148s\n",
      " 71725 44657 248871.561   38  352 254309.728 234308.189  7.87%  29.3 5180s\n",
      " 72123 44851 249128.642   51  236 254309.728 234338.322  7.85%  29.3 5201s\n",
      " 72570 45127 252808.702   50  201 254309.728 234392.208  7.83%  29.3 5246s\n",
      " 72958 45369 248484.854   42  312 254309.728 234404.448  7.83%  29.3 5267s\n",
      " 73401 45596 252941.454   50  257 254309.728 234415.478  7.82%  29.2 5310s\n",
      " 73861 45820 infeasible   37      254309.728 234453.091  7.81%  29.2 5332s\n",
      " 74251 46035 247682.902   33  307 254309.728 234483.259  7.80%  29.2 5356s\n",
      " 74654 46239 246473.827   35  344 254309.728 234515.800  7.78%  29.2 5485s\n",
      "H74828 46239                    254309.72832 234518.889  7.78%  29.2 5485s\n",
      " 75010 46428 250148.939   54  264 254309.728 234547.802  7.77%  29.2 5512s\n",
      " 75435 46644 243321.853   26  384 254309.728 234579.903  7.76%  29.2 5539s\n",
      " 75848 46884 248362.240   35  313 254309.728 234608.786  7.75%  29.2 5564s\n",
      " 76258 47103 247669.353   48  251 254309.728 234625.879  7.74%  29.2 5591s\n",
      " 76684 47357 244377.014   33  340 254309.728 234673.041  7.72%  29.2 5627s\n",
      " 77089 47509 251101.729   37  309 254309.728 234693.558  7.71%  29.2 5668s\n",
      " 77492 47722 252757.196   53  204 254309.728 234722.622  7.70%  29.3 5696s\n",
      " 77906 47945 247815.129   38  288 254309.728 234749.362  7.69%  29.3 5731s\n",
      " 78322 48130 248817.801   32  312 254309.728 234762.432  7.69%  29.3 5756s\n",
      " 78735 48327 239820.664   31  383 254309.728 234810.141  7.67%  29.3 5783s\n",
      " 79139 48546 252051.407   41  258 254309.728 234836.923  7.66%  29.2 5811s\n",
      " 79531 48776 infeasible   53      254309.728 234883.122  7.64%  29.2 5846s\n",
      " 79912 48968 248346.388   36  282 254309.728 234910.933  7.63%  29.2 5873s\n",
      " 80330 49205 238482.102   28  430 254309.728 234935.287  7.62%  29.2 5901s\n",
      " 80751 49394 250201.962   45  322 254309.728 234967.835  7.61%  29.2 5927s\n",
      " 81178 49597 247353.662   26  426 254309.728 234972.533  7.60%  29.2 5950s\n",
      " 81589 49789 244786.017   30  396 254309.728 235012.816  7.59%  29.2 6004s\n",
      " 82000 49996 251129.386   62  246 254309.728 235059.216  7.57%  29.2 6033s\n",
      " 82419 50197 253141.927   66  184 254309.728 235087.227  7.56%  29.2 6061s\n",
      " 82839 50386     cutoff   54      254309.728 235110.650  7.55%  29.2 6102s\n",
      " 83247 50601 242585.213   31  403 254309.728 235135.782  7.54%  29.2 6143s\n",
      " 83653 50813 253490.168   52  196 254309.728 235150.375  7.53%  29.2 6192s\n",
      " 84085 50969 infeasible   45      254309.728 235189.349  7.52%  29.2 6220s\n",
      " 84507 51171 252769.430   43  250 254309.728 235227.924  7.50%  29.2 6266s\n",
      " 84894 51360 247420.944   37  258 254309.728 235268.784  7.49%  29.3 6306s\n",
      " 85319 51567 252892.438   46  217 254309.728 235309.333  7.47%  29.2 6344s\n",
      " 85715 51777 246494.728   54  314 254309.728 235338.522  7.46%  29.2 6373s\n",
      " 86108 51984 252365.895   42  209 254309.728 235370.589  7.45%  29.2 6404s\n",
      " 86519 52210 240484.226   30  393 254309.728 235397.573  7.44%  29.2 6450s\n",
      "H86926 52416                    254309.72785 235401.877  7.43%  29.2 6486s\n",
      " 87332 52613 249671.450   29  334 254309.728 235449.546  7.42%  29.2 6518s\n",
      " 87735 52834 240464.694   31  356 254309.728 235486.473  7.40%  29.2 6556s\n",
      " 88134 53018 253534.503   63  263 254309.728 235506.047  7.39%  29.2 6584s\n",
      " 88548 53189 245499.344   43  387 254309.728 235537.184  7.38%  29.2 6618s\n",
      " 88972 53390 253866.839   53  233 254309.728 235567.690  7.37%  29.2 6651s\n",
      "H89084 53390                    254309.72756 235567.690  7.37%  29.2 6651s\n",
      " 89389 53594 246706.138   39  345 254309.728 235605.446  7.35%  29.2 6715s\n",
      " 89804 53814 252240.537   49  224 254309.728 235615.435  7.35%  29.2 6756s\n",
      " 90234 54005 infeasible   61      254309.728 235637.734  7.34%  29.2 6794s\n",
      "H90632 54268                    254309.72724 235652.947  7.34%  29.2 6836s\n",
      " 91015 54506 245641.415   33  392 254309.727 235685.360  7.32%  29.2 6877s\n",
      " 91409 54733 242355.704   27  378 254309.727 235703.879  7.32%  29.2 6976s\n",
      " 91800 54876 251236.898   49  231 254309.727 235739.895  7.30%  29.2 7011s\n",
      " 92229 55104 infeasible   61      254309.727 235769.161  7.29%  29.2 7055s\n",
      " 92641 55257 245251.620   33  314 254309.727 235787.820  7.28%  29.2 7090s\n",
      " 93065 55489 245352.104   30  359 254309.727 235819.499  7.27%  29.2 7129s\n",
      " 93486 55686 236524.163   26  424 254309.727 235838.324  7.26%  29.1 7164s\n",
      " 93885 55914 250049.966   34  311 254309.727 235858.884  7.26%  29.2 7208s\n",
      " 94318 56152 251811.326   49  219 254309.727 235887.911  7.24%  29.2 7253s\n",
      " 94726 56381 251193.286   51  169 254309.727 235903.494  7.24%  29.2 7280s\n",
      " 95168 56609 246345.092   46  271 254309.727 235916.342  7.23%  29.2 7318s\n",
      " 95557 56854 250142.779   50  207 254309.727 235928.859  7.23%  29.2 7348s\n",
      " 95981 57040 242576.611   29  434 254309.727 235950.671  7.22%  29.2 7382s\n",
      "H96077 57040                    254309.72615 235950.671  7.22%  29.2 7382s\n",
      " 96401 57219 infeasible   51      254309.726 235976.210  7.21%  29.2 7410s\n",
      " 96817 57461 236134.999   32  391 254309.726 236005.589  7.20%  29.2 7445s\n",
      " 97217 57661 246979.293   35  309 254309.726 236040.754  7.18%  29.2 7478s\n",
      " 97649 57876 249637.758   45  324 254309.726 236057.492  7.18%  29.2 7510s\n",
      " 98060 58069     cutoff   38      254309.726 236084.533  7.17%  29.2 7541s\n",
      " 98478 58202 242791.663   30  331 254309.726 236118.748  7.15%  29.2 7574s\n",
      " 98922 58429     cutoff   52      254309.726 236140.167  7.14%  29.2 7607s\n",
      " 99338 58644 245390.684   44  256 254309.726 236153.468  7.14%  29.1 7631s\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 99748 58826 251523.099   44  234 254309.726 236178.993  7.13%  29.1 7660s\n",
      " 100180 59026 252115.173   36  278 254309.726 236203.938  7.12%  29.1 7705s\n",
      " 100608 59247 242097.494   42  361 254309.726 236228.908  7.11%  29.1 7739s\n",
      " 101019 59455 240636.508   32  349 254309.726 236248.899  7.10%  29.1 7777s\n",
      " 101416 59683 247020.789   43  346 254309.726 236270.467  7.09%  29.1 7813s\n",
      " 101859 59932 infeasible   58      254309.726 236294.046  7.08%  29.1 7851s\n",
      " 102268 60146 251019.194   39  301 254309.726 236301.818  7.08%  29.1 7887s\n",
      " 102692 60351 253574.358   48  240 254309.726 236313.548  7.08%  29.1 7921s\n",
      " 103132 60572 252860.101   50  309 254309.726 236331.666  7.07%  29.1 7971s\n",
      " 103549 60749 247491.567   51  272 254309.726 236344.769  7.06%  29.1 8001s\n",
      " 103994 60948 249068.574   44  256 254309.726 236366.020  7.06%  29.1 8045s\n",
      " 104421 61159 243663.184   30  367 254309.726 236385.009  7.05%  29.1 8098s\n",
      " 104898 61350 244291.355   23  469 254309.726 236421.502  7.03%  29.1 8123s\n",
      " 105299 61531 253358.737   41  271 254309.726 236453.753  7.02%  29.1 8166s\n"
     ]
    }
   ],
   "source": [
    "# 原模型\n",
    "lin1 = gp.quicksum(f[j]*y[j] for j in J)\n",
    "lin2 = gp.quicksum(gp.quicksum(gp.quicksum(h[j,k]*s*v[j,s,k] for s in L[j,k]) for k in K) for j in J)\n",
    "lin3 = gp.quicksum(gp.quicksum(gp.quicksum(gp.quicksum(gp.quicksum((c_4[i,m,j,k])*z[i,m,j,n,k]*D[i,k] for i in I_jk[j,k]) for m in M) for k in K) for j in J) for n in I)\n",
    "m.setObjective(lin1 + lin2 + lin3, sense=GRB.MINIMIZE)\n",
    "m.update()\n",
    "m.optimize()"
   ]
  },
  {
   "cell_type": "raw",
   "id": "f87d0b01",
   "metadata": {},
   "source": [
    "# 不考虑期望成本\n",
    "lin1 = gp.quicksum(f[j]*y[j] for j in J)\n",
    "lin2 = gp.quicksum(gp.quicksum(gp.quicksum(h[j,k]*s*v[j,s,k] for s in L[j,k]) for k in K) for j in J)\n",
    "lin3 = gp.quicksum(gp.quicksum(gp.quicksum(gp.quicksum(c_4[i,m,j,k]*x[i,m,j,k]*D[i,k] for i in I_jk[j,k]) for m in M) for k in K) for j in J)\n",
    "m.setObjective(lin1 + lin2 + lin3, sense=GRB.MINIMIZE)\n",
    "m.update()\n",
    "m.optimize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "geographic-anatomy",
   "metadata": {},
   "outputs": [],
   "source": [
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4fca19d8",
   "metadata": {},
   "source": [
    "### 选址成本，库存成本，运输成本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "23c71667",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 原模型\n",
    "Cost_location = sum(f[j]*y[j].x for j in J)\n",
    "Cost_inventory = sum(sum(sum(h[j,k]*s*v[j,s,k].x for s in L[j,k]) for k in K) for j in J)\n",
    "Cost_trans = sum(sum(sum(sum(sum((c_4[i,m,j,k])*z[i,m,j,n,k].x*D[i,k] for i in I_jk[j,k]) for m in M) for k in K) for j in J) for n in I)\n",
    "print(Cost_location,Cost_inventory,Cost_trans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "corporate-dynamics",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "Cost_location + Cost_inventory + Cost_trans"
   ]
  },
  {
   "cell_type": "raw",
   "id": "74bbceed",
   "metadata": {},
   "source": [
    "# 不考虑期望成本\n",
    "Cost_location = sum(f[j]*y[j].x for j in J)\n",
    "Cost_inventory = sum(sum(sum(h[j,k]*s*v[j,s,k].x for s in L[j,k]) for k in K) for j in J)\n",
    "Cost_trans = sum(sum(sum(sum(c_4[i,m,j,k]*x[i,m,j,k].x*D[i,k] for i in I_jk[j,k]) for m in M) for k in K) for j in J)\n",
    "print(Cost_location,Cost_inventory,Cost_trans)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "excited-functionality",
   "metadata": {},
   "source": [
    "### 检验\n",
    "##### 1. 每个客户必须且仅能分配给一个快递点和一个本地库\n",
    "##### 2. 保证被本地库j服务的所有客户都必须满足客户的服务水平\n",
    "##### 3. 库存水平约束"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "three-percentage",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1\n",
    "covers = dict() # 备选点j cover的（客户j, 备件k）\n",
    "routes_fori = dict() # （客户i，备件k）经过的（快运点m，本地库j）\n",
    "for i in I:\n",
    "    for m in M:\n",
    "        for j in J:\n",
    "            for k in K:\n",
    "                if abs(x[i,m,j,k].x - 1) < tlr_model:\n",
    "                    if j not in covers:\n",
    "                        covers[j] = set()\n",
    "                    covers[j].add((i,k))\n",
    "                    if (i,k) in routes_fori:\n",
    "                        raise \"错误\"\n",
    "                    routes_fori[i,k] = (m,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "instructional-theorem",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc10fe9b",
   "metadata": {},
   "source": [
    "### 查询结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "british-failing",
   "metadata": {},
   "outputs": [],
   "source": [
    "tlr = 0.001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "specific-elder",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 开放方案\n",
    "for j in J:\n",
    "    if abs(y[j].x - 1) < tlr:\n",
    "        print(j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "vulnerable-journalism",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 顾客-产品分配方案\n",
    "ll = []\n",
    "have_error = {}\n",
    "for i in I:\n",
    "    for k in K:\n",
    "        for m in M:\n",
    "            for j in J:\n",
    "                if abs(x[i,m,j,k].x - 1) < tlr:\n",
    "                    if x[i,m,j,k].x != 1:\n",
    "                        have_error[i,m,j,k] = x[i,m,j,k].x\n",
    "                    if D[i,k] == 0:\n",
    "                        continue\n",
    "                    if m >= M_num - virtual_num:\n",
    "                        ll.append(-1)\n",
    "                        print('({0}, {1})分配的仓库是{2},运输方式是直运'.format(i,k,j))\n",
    "                    else:\n",
    "                        ll.append(m)\n",
    "                        print('({0}, {1})分配的仓库是{2},运输方式是{3}'.format(i,k,j,m))\n",
    "print(ll)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "infrared-cameroon",
   "metadata": {},
   "outputs": [],
   "source": [
    "error = {}\n",
    "for i in I:\n",
    "    for m in M:\n",
    "        for j in J:\n",
    "            for n in I:\n",
    "                for k in K:\n",
    "                    if abs(z[i,m,j,n,k].x -1) < tlr and z[i,m,j,n,k].x != 1:\n",
    "                        error[i,m,j,n,k] = z[i,m,j,n,k].x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "hydraulic-likelihood",
   "metadata": {},
   "outputs": [],
   "source": [
    "error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "absolute-nebraska",
   "metadata": {},
   "outputs": [],
   "source": [
    "j=1\n",
    "m=1\n",
    "k=1\n",
    "n=9\n",
    "i=6\n",
    "error_t = (c_4[i,m,j,k]*ijk_b[n,j,k] + c_3[0,i,k]*(1-ijk_b[n,j,k]))*(1-z[i,m,j,n,k].x)*D[i,k]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "periodic-friday",
   "metadata": {},
   "outputs": [],
   "source": [
    "Cost_trans+error_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "broad-desperate",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 库存水平\n",
    "for j in J:\n",
    "    for s in range(max_s+1):\n",
    "        for k in K:\n",
    "            if abs(v[j,s,k].x - 1) < tlr:\n",
    "                print(\"仓库{0}对产品{1}的库存水平为：{2}\".format(j,k,s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "british-explorer",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.argmax(alpha[:, 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "minor-constraint",
   "metadata": {},
   "outputs": [],
   "source": [
    "i = 9\n",
    "j = 1\n",
    "k = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "isolated-representation",
   "metadata": {},
   "outputs": [],
   "source": [
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "later-enhancement",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "miu[i,j,k,7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "gentle-click",
   "metadata": {},
   "outputs": [],
   "source": [
    "s_level"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "comic-ensemble",
   "metadata": {},
   "outputs": [],
   "source": [
    "miu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fourth-packaging",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.sum(D[:, 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "excessive-thousand",
   "metadata": {},
   "outputs": [],
   "source": [
    "D"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d972ba0",
   "metadata": {},
   "outputs": [],
   "source": [
    "tt = 0.000001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "957b0540",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "for j in range(len(J)):\n",
    "    if abs(y[j].x - 1)< tt:\n",
    "        print(j)\n",
    "for i in range(len(I)):\n",
    "    for m in range(len(M)):\n",
    "        for j in range(len(J)):\n",
    "            for k in range(len(K)):\n",
    "                if abs(x[i,m,j,k].x - 1) < tt:\n",
    "                    print(i,m,j,k)\n",
    "for j in range(len(J)):\n",
    "    for s in range(max_s+1):\n",
    "        for k in range(len(K)):\n",
    "            if abs(v[j,s,k].x - 1) < tt:\n",
    "                print(j,s,k)\n",
    "for j in range(len(J)):\n",
    "    for i in range(len(I)):\n",
    "        for k in range(len(K)):\n",
    "            if abs(w[j,i,k].x -1) < tt:\n",
    "                print(j,i,k)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "3b9a8c2a",
   "metadata": {},
   "source": [
    "for j in range(len(J)):\n",
    "    if abs(y[j].x - 1) > tt and abs(y[j].x) > tt:\n",
    "        print(j)\n",
    "for i in range(len(I)):\n",
    "    for m in range(len(M)):\n",
    "        for j in range(len(J)):\n",
    "            for k in range(len(K)):\n",
    "                if abs(x[i,m,j,k].x - 1) > tt and abs(x[i,m,j,k].x) > tt:\n",
    "                    print(i,m,j,k)\n",
    "for j in range(len(J)):\n",
    "    for s in range(max_s+1):\n",
    "        for k in range(len(K)):\n",
    "            if abs(v[j,s,k].x - 1) > tt and abs(v[j,s,k].x) > tt:\n",
    "                print(j,s,k)\n",
    "for j in range(len(J)):\n",
    "    for i in range(len(I)):\n",
    "        for k in range(len(K)):\n",
    "            if abs(w[j,i,k].x -1) > tt and abs(w[j,i,k].x) > tt:\n",
    "                print(j,i,k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "listed-chaos",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "moved-dispute",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "casual-mathematics",
   "metadata": {},
   "outputs": [],
   "source": [
    "fl = open('xx.txt', 'w')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "classical-northern",
   "metadata": {},
   "outputs": [],
   "source": [
    "type(fl)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "complete-locking",
   "metadata": {},
   "outputs": [],
   "source": [
    "fl.__class__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "excessive-delaware",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
